package com.ld.security.common.mybatis.util;

import com.baomidou.dynamic.datasource.DynamicDataSourceCreator;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.util.Map;


public class DataSourceUtil {



    private static DynamicRoutingDataSource dynamicRoutingDataSource;

    public static void addDataSource(String db,DataSource dataSource){
        dynamicRoutingDataSource.addDataSource(db,dataSource);
    }

    public static void removeDataSource(String db){
        dynamicRoutingDataSource.removeDataSource(db);
    }

    public static DynamicRoutingDataSource getDynamicRoutingDataSource() {
        return dynamicRoutingDataSource;
    }


    public static Map<String,DataSource> getCurrentDataSources(){
        return dynamicRoutingDataSource.getCurrentDataSources();
    }

    public static DataSource getDataSource(String db){

        return dynamicRoutingDataSource.getDataSource(db);
    }

    public static void setDynamicRoutingDataSource(DynamicRoutingDataSource dynamicRoutingDataSource) {
        DataSourceUtil.dynamicRoutingDataSource = dynamicRoutingDataSource;
    }
}
